<script>
    function auto_form(option) {
        var step = {};
        var index;
        var _form = {
            data: {},       //数据集合
            label: {},      //字段集合
            labelFun: function () {
                if (!this.label.hasOwnProperty()) {
                    var step = {};
                    for (index in this.data) {
                        if (this.data.hasOwnProperty(index)) {
                            step[index] = this.data[index].label;
                        }
                    }
                    this.label = step;
                }
            },
            init: function () {
                this.labelFun();
                return this;
            },
            get: function (number, numberN) {
                if (typeof number === 'undefined')return;
                var step = {};
                if (typeof numberN === 'undefined') {
                    for (index in this.data) {
                        if (this.data.hasOwnProperty(index)) {
                            if ($.inArray(number, this.data[index].data) !== -1) {
                                if (typeof this.data[index].Default !== 'undefined') step[index] = this.data[index].Default;
                                else step[index] = '';
                            }
                        }
                    }
                } else {
                    for (index in this.data) {
                        if (this.data.hasOwnProperty(index)) {
                            if (($.inArray(number, this.data[index].data) !== -1) && ($.inArray(numberN, this.data[index].data) === -1)) {
                                if (typeof this.data[index].Default !== 'undefined') step[index] = this.data[index].Default;
                                else step[index] = '';
                            }
                        }
                    }
                }
                return step;
            },
            pop: function (O, number) {
                if (typeof O === 'undefined')return;
                var row = O['form_' + number];
                var cur = O['current'];
                var step = this.get(number);

                allPrposCb(step, function (obj2, index) {
                    if (typeof row[index] !== 'undefined') {
                        if (row[index] instanceof Date) {
                            step[index] = tsf_date(row[index]);
                        }
                        else if (row[index] instanceof Array) {
                            for (var i in row[index]) {
                                if (row[index].hasOwnProperty(i)) step[index + i] = tsf_date(row[index][i]);
                            }
                            delete step[index];
                        }
                        else {
                            step[index] = row[index];
                        }
                    }
                });

                step.pageNum = cur.pageNum;
                step.pageSize = cur.pageSize;
                step.draw = 0;

                return step;
            }
        };
        return Object.create(_form, autoValue({data: option}));
    }                //核心 - 表单字段
    function autoVue(data, methods, other) {
        function auto_data(option, prop) {
            var _data = {
                data: {},                 // 自定义值
                Default: {
                    current: _current(),
                    multiSelect: false,
                    showLoading: false,
                    pickerOption0: _pickerOptions(0),
                    pickerOption10: _pickerOptions(10),
                    pickerOption100: _pickerOptions(100),
                    pickerOption110: _pickerOptions(110)
                },           // 默认值
                init: function () {
                    var step = Object.create(null);
                    var index = '';
                    for (index in this.Default) {
                        if (this.Default.hasOwnProperty(index)) {
                            step[index] = this.Default[index];
                        }
                    }
                    if (typeof prop !== 'undefined') for (index = 0; index < prop.length; index++) {
                        step[prop[index].name] = prop[index].data;
                    }
                    for (index in this.data) {
                        if (this.data.hasOwnProperty(index)) {
                            step[index] = this.data[index];
                        }
                    }
                    return function () {
                        return step
                    };
                }   // 值
            };
            return Object.create(_data, autoValue({data: option}));
        }

        function auto_methods(option, prop) {
            var _methods = {
                data: {},                 // 自定义值
                Default: {
                    handleSizeChange: function (val) {
                        this.current.pageSize = val;
                        p[0].post((_option ? this.pop : this.option));
                    },
                    handleCurrentChange: function (val) {
                        this.current.currentPage = val;
                        p[0].post((_option ? this.pop : this.option));
                    }
                },           // 默认值
                init: function () {
                    var step = Object.create(null);
                    var index = '';
                    for (index in this.Default) {
                        if (this.Default.hasOwnProperty(index)) {
                            step[index] = this.Default[index];
                        }
                    }
                    if (typeof prop !== 'undefined') for (index = 0; index < prop.length; index++) {
                        step[prop[index].name] = prop[index].fun;
                    }
                    for (index in this.data) {
                        if (this.data.hasOwnProperty(index)) {
                            step[index] = this.data[index];
                        }
                    }
                    return step;
                }   // 值
            };
            return Object.create(_methods, autoValue({data: option}));
        }

        var prop = [];
        for (var i = 3; i < arguments.length; i++) {
            prop.push(arguments[i])
        }
        _Vue = {
            data: auto_data(data, prop).init(),
            methods: auto_methods(methods, prop).init(),
            template: "",
            computed: {
                option: function () {
                    return _form.pop(this, 2);
                },
                pop: function () {
                    return _form.pop(this, 3);
                }
            },
            watch: {}
        };
        return Object.create(_Vue, autoValue(other));
    }    //核心 - 自动配置Vue
    function ldd(label, data, Default) {
        var step = Object.create(null);
        step.label = label;
        step.data = data;
        step.Default = Default;
        return step;
    }        //核心 - 表单 自动配置
    function auto_dialog(option) {
        var _dialog = {
            name: '',
            data: {},                 // 自定义值
            Default: {
                dv: false,   //弹出层 控制
            },           // 默认值
            val: function () {
                if (this.name === '') return;
                var step = Object.create(null);
                var index = '';
                for (index in this.Default) {
                    if (this.Default.hasOwnProperty(index)) {
                        step[index] = this.Default[index];
                    }
                }
                for (index in this.data) {
                    if (this.data.hasOwnProperty(index)) {
                        step[index] = this.data[index];
                    }
                }
                return step;
            }, // 值
            fun: function (str, obj) {
            }
        };
        return Object.create(_dialog, autoValue(option));
    }              //核心 - 新建弹出层


    /**
     * @param __form  V-model前缀
     *
     * @param label
     *          1. "" 正常解析 其余不解析
     *
     * @returns {string}
     */
    function pretreatmentVue(__form, label) {
        var string = '';
        for (var index in label) {
            if (label.hasOwnProperty(index)) {
                var temp = label[index];
                if (temp.constructor === String) {
                    string += '<el-input\
    @change="selectReturn"\
    class="input"\
    v-model="' + __form + '.' + index + '"\
    icon="search"\
    :placeholder="form.' + index + '"></el-input>'
                }
                else if (temp.constructor === Array) {
                    string += '<el-date-picker\
    v-model="' + __form + '.' + index + '"\
                    type="daterange"\
                    align="right"\
                :placeholder="form.' + index + '"\
                class="datePicker"\
                :picker-options="pickerOption0">\
                        </el-date-picker>'

                } else if (temp.constructor === Object) {
                    string += '<el-date-picker\
    v-model="' + __form + '.' + index + '"\
                    type="date"\
                    align="right"\
                :placeholder="form.' + index + '"\
                class="datePicker"\
                :picker-options="pickerOption10">\
                        </el-date-picker>'

                } else if (temp.constructor === Number) {
                    string += ' <el-select\
                    @visible-change="selectReturn"\
    v-model="' + __form + '.' + index + '"\
                :placeholder="form.' + index + '">\
                        <el-option :label="obj.baName" :value="obj.baArehouseId"\
                    v-for="obj of baseArehouses"></el-option>\
                        </el-select>'
                }
            }
        }
        return string;
    }


    /*--------------------------------------虚拟数据------------------------------*/

    var _form = auto_form({
        rk_rkdj_id: ldd('明细id', [1, 4, 5]),
        sfrq: ldd('始发日期', [1, 2, 3]),
        dhsj: ldd('到货日期', [1, 2, 3]),
        dbdd: ldd('到货日期', [1, 3]),
        cys: ldd('调拨地点', [1, 3]),
        cph: ldd('承运商', [1, 3]),
        shr: ldd('车牌号', [1, 3]),
        shck: ldd('收货人', [1, 2, 3], window.dbmessage.baseArehouses[0].baArehouseId),
        dh: ldd('收货仓库', [1, 2, 3]),
        dbdh: ldd('单号', [1, 3]),
        cyts: ldd('调拨单号', [1]),
        cyxs: ldd('承运件数(台)', [1]),
        cytj: ldd('承运件数(箱)', [1]),
        wlbm: ldd('方数', [1]),
        wlms: ldd('物料编号', [1, 3]),
        ts: ldd('物料描述', [1, 3]),
        js: ldd('台数', [1]),
        tj: ldd('件数', [1]),
        dbpswb: ldd('方数', [1]),
        ytpswb: ldd('调拨破损外包', [1]),
        dbpsnb: ldd('源头破损外包', [1]),
        ytpsnb: ldd('调拨破损内保', [1]),
        ycyy: ldd('源头破损内保', [1]),
        cljg: ldd('异常原因', [1]),
        psts: ldd('处理结果', [1]),
        jssj: ldd('破损台数', [1]),
        rksWjReason: ldd('结算时间', [4]),
        rksBfdh: ldd('完结原因', [4])
    }).init();

    var _select = auto_dialog({
        name: 'select',
        data: _form.get(3),
        fun: function (number) {
            switch (number) {
                case 1:  //submit
                    p[0].post(obj.form_pop);
                    break;
            }
        }
    });

    var _vue = autoVue({
        form: _form.label,
        form_1: _form.get(1),
        form_6: _form.get(1),
        form_2: _form.get(2),
        form_4: _form.get(4),
        form_5: _form.get(1, 5)
    }, {}, {
        template: "#tool-print-template",
        watch: {}
    }, _select);

    var step = Object.create(null);

    step.data = _vue.data;
    step.template = _vue.template;
    step.watch = _vue.watch;
    step.computed = _vue.computed;
    step.methods = _vue.methods;

    /*--------------------------------------输出------------------------------*/

    console.log(JSON.stringify(step));

</script>